/**
 * Created by c on 2017-11-23.
 */
$(function(){
    //加载模态框
    $("#updateDrug").dialog({
        title:"采购明细信息修改",
        btnValue:"修改",
        addBind:function(){
            var param = $("#updateDrug form").serialize();
            console.log(param)
            $.post(ctx+"/pur/updels",param,function(flag){
                $("#updateDrug").dialog("close");
                if(flag=="true"){
                    swal({
                        title:"操作提示",
                        text:"修改成功!",
                        type:"success",
                    }).then(function(){
                        var planNum = $("#updateDrug form input[name=planNum]").val();
                        location.href=ctx+"/pur/purEdit?planNum="+planNum;
                    })
                }else{
                    toastr.error("操作提示","系统繁忙,修改失败!");
                }
            },"text");
        }
    });
    //设置table背景颜色
    $("table#delTable").children().find("#back").css({"background-color":"#838383","color":"white"})
})
// swal({
//     title:"操作提示",
//     text:"提交成功,请留意审核!",
//     type:"success",
// }).then(function(){
//     location.href=ctx+"/pur/purview/index";
// })

function subPurZhu(){
    swal({
        title:"操作提示",
        text:"提交成功,请留意审核!",
        type:"success",
    }).then(function(){
        location.href=ctx+"/pur/purview/index";
    })
}
function updateDrug(td){
    var delId = $(td).parent().parent().children(":eq(0)").html();
    var param = "delId="+delId;
    $("#updateDrug").dialog("open");
    $.post(ctx+"/pur/getPurdetails",param,function(purdels){
        $("#updateDrug form").setForm(purdels);
        $("#updateDrug form input[name=drugName]").val(purdels.druginfo.drugName);
    },"json");
}

function deleteDels(td){
    var delId = $(td).parent().parent().children(":eq(0)").html();
    var $tr = $(td).parent().parent();
    var param = "delId="+delId;
    swal({
        title:"确认提示",
        text:"确认一处此采购信息吗？",
        type:"warning",
        showCancelButton:true,
        closeOnConfirm:false,
        confirmButtonText:"删除",
        confirmButtonColor:"#DD6B55",
        cancelButtonText: "取消"
    }).then(function(){
        $.post(ctx+"/pur/deldelsByid",param,function(flag){
            if(flag=="true"){
                toastr.success("操作提示","移除成功!");
                $tr.remove();
            } else {
                toastr.error("操作提示","系统繁忙,移除失败!");
            }
        },"text");
    });

}
